home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / ddj0492.zip / DFLT11.ZIP / LISTS.C < prev    next >
Text File  |  1992-01-27  |  4KB  |  165 lines

  1. /* --------------- lists.c -------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. struct LinkedList Focus;
  6.  
  7. /* --- set focus to the window beneath the one specified --- */
  8. void SetPrevFocus(WINDOW wnd)
  9. {
  10.     if (wnd != NULL && wnd == inFocus)    {
  11.         WINDOW wnd1 = wnd;
  12.         while (TRUE)    {
  13.             if ((wnd1 = PrevWindow(wnd1)) == NULL)
  14.                 wnd1 = Focus.LastWindow;
  15.             if (wnd1 == NULL || wnd1 == wnd)
  16.                 return;
  17.             if (isVisible(wnd1))
  18.                 break;
  19.         }
  20.         if (wnd1 != NULL)
  21.             SendMessage(wnd1, SETFOCUS, TRUE, 0);
  22.     }
  23. }
  24.  
  25. /* this function assumes that wnd is in the Focus linked list */
  26. static WINDOW SearchFocusNext(WINDOW wnd, WINDOW pwnd)
  27. {
  28.     WINDOW wnd1 = wnd;
  29.  
  30.     if (wnd != NULL)    {
  31.         while (TRUE)    {
  32.             if ((wnd1 = NextWindow(wnd1)) == NULL)
  33.                 wnd1 = Focus.FirstWindow;
  34.             if (wnd1 == wnd)
  35.                 return NULL;
  36.             if (wnd1 != NULL)
  37.                 if (pwnd == NULL || pwnd == GetParent(wnd1))
  38.                     break;
  39.         }
  40.     }
  41.     return wnd1;
  42. }
  43.  
  44. /* ----- set focus to the next sibling ----- */
  45. void SetNextFocus(WINDOW wnd)
  46. {
  47.     WINDOW wnd1;
  48.  
  49.     if (wnd != inFocus)
  50.         return;
  51.     if ((wnd1 = SearchFocusNext(wnd, GetParent(wnd)))==NULL)
  52.         wnd1 = SearchFocusNext(wnd, NULL);
  53.     if (wnd1 != NULL)
  54.         SendMessage(wnd1, SETFOCUS, TRUE, 0);
  55. }
  56.  
  57. /* ---- remove a window from the Focus linked list ---- */
  58. void RemoveFocusWindow(WINDOW wnd)
  59. {
  60.     if (wnd != NULL)    {
  61.         if (PrevWindow(wnd) != NULL)
  62.             NextWindow(PrevWindow(wnd)) = NextWindow(wnd);
  63.         if (NextWindow(wnd) != NULL)
  64.             PrevWindow(NextWindow(wnd)) = PrevWindow(wnd);
  65.         if (wnd == Focus.FirstWindow)
  66.             Focus.FirstWindow = NextWindow(wnd);
  67.         if (wnd == Focus.LastWindow)
  68.             Focus.LastWindow = PrevWindow(wnd);
  69.     }
  70. }
  71.  
  72. /* ---- append a window to the Focus linked list ---- */
  73. void AppendFocusWindow(WINDOW wnd)
  74. {
  75.     if (wnd != NULL)    {
  76.         if (Focus.FirstWindow == NULL)
  77.             Focus.FirstWindow = wnd;
  78.         if (Focus.LastWindow != NULL)
  79.             NextWindow(Focus.LastWindow) = wnd;
  80.         PrevWindow(wnd) = Focus.LastWindow;
  81.         NextWindow(wnd) = NULL;
  82.         Focus.LastWindow = wnd;
  83.     }
  84. }
  85.  
  86. /* ---- add a window to the beginning of the Focus linked list ---- */
  87. void PrependFocusWindow(WINDOW wnd)
  88. {
  89.     if (wnd != NULL)    {
  90.         if (Focus.LastWindow == NULL)
  91.             Focus.LastWindow = wnd;
  92.         if (Focus.FirstWindow != NULL)
  93.             PrevWindow(Focus.FirstWindow) = wnd;
  94.         NextWindow(wnd) = Focus.FirstWindow;
  95.         PrevWindow(wnd) = NULL;
  96.         Focus.FirstWindow = wnd;
  97.     }
  98. }
  99.  
  100. /* -------- get the first child of a parent window ------- */
  101. WINDOW GetFirstChild(WINDOW wnd)
  102. {
  103.     WINDOW ThisWindow = NULL;
  104.     if (wnd->ChildCt)
  105.         ThisWindow = *(wnd->Children);
  106.     return ThisWindow;
  107. }
  108.  
  109. /* -------- get the next child of a parent window ------- */
  110. WINDOW GetNextChild(WINDOW wnd, WINDOW ThisWindow)
  111. {
  112.     if (ThisWindow != NULL)    {
  113.         int i;
  114.         for (i = 0; i < wnd->ChildCt; i++)
  115.             if (ThisWindow == *(wnd->Children+i))
  116.                 break;
  117.         if (++i < wnd->ChildCt)
  118.             ThisWindow = *(wnd->Children+i);
  119.         else
  120.             ThisWindow = NULL;
  121.     }
  122.     return ThisWindow;
  123. }
  124.  
  125. /* -- get first child of parent window from the Focus list -- */
  126. WINDOW GetFirstFocusChild(WINDOW wnd)
  127. {
  128.     WINDOW ThisWindow = Focus.FirstWindow;
  129.     while (ThisWindow != NULL)    {
  130.         if (GetParent(ThisWindow) == wnd)
  131.             break;
  132.         ThisWindow = NextWindow(ThisWindow);
  133.     }
  134.     return ThisWindow;
  135. }
  136.  
  137. /* -- get next child of parent window from the Focus list -- */
  138. WINDOW GetNextFocusChild(WINDOW wnd, WINDOW ThisWindow)
  139. {
  140.     while (ThisWindow != NULL)    {
  141.         ThisWindow = NextWindow(ThisWindow);
  142.         if (ThisWindow != NULL)
  143.             if (GetParent(ThisWindow) == wnd)
  144.                 break;
  145.     }
  146.     return ThisWindow;
  147. }
  148.  
  149. /* --- bypass system windows when stepping through focus --- */
  150. void SkipSystemWindows(int Prev)
  151. {
  152.     int cl, ct = 0;
  153.     while ((cl = GetClass(inFocus)) == MENUBAR ||
  154.             cl == APPLICATION || cl == STATUSBAR)    {
  155.         if (Prev)
  156.             SetPrevFocus(inFocus);
  157.         else 
  158.             SetNextFocus(inFocus);
  159.         if (++ct == 3)
  160.             break;
  161.     }
  162. }
  163.  
  164.  
  165.